<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <table border="1" width="1024">
            <tr>
                <th>Booking id</th>
                <th>Customer</th>
                <th>Booking Date</th>
                <th>Check-in Date</th>
                <th>Check-out Date</th>
                <th>Total</th>
                <th>Paid</th>
                <th>Paid Date</th>
                <th>Remain</th>
                <th>Fees</th>
                <th>Complete payment Time</th>
            </tr>
<?php
    $_st = $_GET['status_id'];
    $_st = ($_st == '') ? 1 : $_st;

    include '../connectdb.php';
    $q = "select booking.*, customer.customer_fname, customer.customer_lname from booking, customer where booking.customer_id=customer.customer_id";
    $result = mysqli_query($link, $q);
    while ($row = mysqli_fetch_array($result)){ 
        $total = $row['total_price'];
        $deposit = $row['deposit'];
        $remain = $total - $deposit;
        $q = "select min(booking_detail.date) as mindate, max(booking_detail.date) as maxdate, status_name, booking_detail.status_id from booking_detail, status where status.status_id=booking_detail.status_id and booking_id=".$row['booking_id'];
        $res = mysqli_query($link, $q);
        $r = mysqli_fetch_array($res);
        $cod = date ("Y-m-d", strtotime("+1 day", strtotime($r['maxdate'])));
        $status = $r['status_name'];
        if ($_st == $r['status_id']) {
?>
            <tr>
                <td><a href="#"><?php echo $row['booking_id'];?></a></td>
                <td><?php echo $row['customer_fname'].' '.$row['customer_lname'];?></td>
                <td><?php echo $row['booking_date'];?></td>
                <td><?php echo $r['mindate'];?></td>
                <td><?php echo $cod;?></td>
                <td><?php echo $total;?></td>
                <td><?php echo $deposit;?></td>
                <td><?php echo $row['deposit_date'];?></td>
                <td><?php echo $remain;?></td>
                <td><?php echo $row['total_fee'];?></td>
                <td><?php echo $row['checkout_date'];?></td>
            </tr>
<?php
        }
    }
?>
        </table>
    </body>
</html>